#include <iostream>
#include <cstdio>

using namespace std;

class SegmentTree
{
    static const int MAXN=100100*3;
    public:
    class Node
    {
        public:
        int ld,rd;
        int w;
        void set(int a,int b,int c){ld=a,rd=b,w=c;}
    };
    Node *node;
    inline int lc(int t){return t*2;}
    inline int rc(int t){return t*2+1;}
    SegmentTree(){node=new Node[MAXN];}
    void init(int n)
    {
        build(1,1,n,1);
    }
    void build(int pos,int a,int b,int c)
    {
        node[pos].set(a,b,c);
        int mid=(a+b)/2;
        if(a<b)
        {
            build(lc(pos),a,mid,c);
            build(rc(pos),mid+1,b,c);
        }
    }
    void set(int pos,int a,int b,int colour)
    {
        Node *nt=&node[pos];
        int mid=(nt->ld+nt->rd)/2;
        if(a<=nt->ld&&nt->rd<=b)
        {
            nt->w=1<<(colour-1);
        }
        else
        {
            if(getColour(nt->w)<=1) node[lc(pos)].w=node[rc(pos)].w=nt->w;
            if(mid>=a)set(lc(pos),a,b,colour);
            if(mid<b)set(rc(pos),a,b,colour);
            nt->w=node[lc(pos)].w|node[rc(pos)].w;
        }
    }
    int query(int pos,int a,int b)
    {
        Node *nt=&node[pos];
        int mid=(nt->ld+nt->rd)/2;
        if((a<=nt->ld&&nt->rd<=b)||(getColour(nt->w)<=1))
        {
            return nt->w;
        }
        else
        {
            int t1=0,t2=0;
            if(mid>=a)t1=query(lc(pos),a,b);
            if(mid<b)t2=query(rc(pos),a,b);
            return t1|t2;
        }
    }
    int getColour(int t)
    {
        int cnt=0;
        while(t)
        {
            if(t&1) cnt++;
            t>>=1;
        }
        return cnt;
    }
};

int main()
{
    int L,T,O;
    SegmentTree t;
    while(cin>>L>>T>>O)
    {
        t.init(L);
        while(O--)
        {
            int a,b,c;
            char ch[5];
            scanf("%s",ch);
            if(ch[0]=='C')
            {
                scanf("%d%d%d",&a,&b,&c);
                if(a>b) swap(a,b);
                t.set(1,a,b,c);
            }
            else
            {
                scanf("%d%d",&a,&b);
                if(a>b) swap(a,b);
                cout<<t.getColour(t.query(1,a,b))<<endl;
            }
        }
    }
    return 0;
}
